// pages/desc/desc.js
const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象c.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bd:'',
    bd1:'',
    c:[],
    d:[],
    index1:100,
    index2:100,
    bd2:'',
    bd3:'',
    zfad:false,
    phone:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      c: JSON.parse(options.arr1),
      d: JSON.parse(options.arr2),
      bd:options.bd,
      bd1:options.bd1
    })
  },
  seone(e){
    this.setData({
      index1: parseInt(e.currentTarget.dataset.index),
      bd2: e.currentTarget.dataset.id
    })
  },
  setwo(e){
    this.setData({
      index2: parseInt(e.currentTarget.dataset.index),
      bd3: e.currentTarget.dataset.id
    })
  },
  overd(e){
    this.setData({
      zfad:true
    })
  },

  jian(){
    let that =this;
    let data ={
      uid:wx.getStorageSync('members')['id'],
      phone:that.data.phone
    }
    index.jian(data,(res)=>{
      if(res.code == 200){
          wx.showToast({
            title: res.msg,
            icon:"none",
            duration:1000
          })
      }else{
        wx.showToast({
          title: res.msg,
          icon: "none",
          duration: 1000
        })
      }
    })
  },

  getrcoe(){
    let that =this;
    let data ={
      uid: wx.getStorageSync('members')['id'],
      pain:that.data.bd,
      mode:that.data.bd1,
      time:that.data.bd2,
      past:that.data.bd3
    };
    index.getrcoe(data,(res)=>{
      if(res.code== 200){
        that.setData({
          zfad: true
        })

      }else{
        Function.layer(res.msg);
      }
    })
  },
  getPhonev:function(e){
    let that=this;
    let phone = e.detail.value;
    that.setData({
      phone: phone
    })
  },
  gphone(){
    let that=this;
    if (that.data.phone==''){
      Function.layer("手机号码不能为空");
      return;
    } else if (!app.validatePhone(that.data.phone)){
      Function.layer("手机号码有误");
      return;
    }
    let data={
      uid: wx.getStorageSync('members').id,
      phone: that.data.phone
    }
    index.jian(data,(res)=>{
      if(res.code==200){
        Function.layer('你已领取'+res.data+"红包");
        setTimeout(function(){
          wx.switchTab({
            url: '/pages/my/mine/mine'
          })
        },2000)
        that.setData({
          zfad: false
        })
      }else{
          Function.layer(res.msg);
          if (res.msg == '请先绑定手机') {
            wx.showModal({
              title: '提示',
              content: '你还未绑定手机是否前往绑定',
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/pages/shouye/bindMobile/bindMobile'
                  })
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }
      }
    })
    // this.setData({
    //   phone:e.detail.value
    // })
  },
  hidezz(){
    // this.jian();
    // this.setData({ zfad:false});
    wx.switchTab({
      url: '/pages/my/mine/mine'
    })
  }





})